# widgets/workstep_config_widget.py
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, 
                             QGroupBox)
from PySide6.QtGui import QFont, QIcon
from PySide6.QtCore import Signal
from components.workstep_cycle_tool import WorkstepCycleTool

class WorkstepConfigWidget(QWidget):
    """4. 工步配置Tab：负责工步组合、循环设置（依赖自定义组件WorkstepCycleTool）"""
    next_clicked = Signal()  # 下一步
    prev_clicked = Signal()

    def __init__(self, parent=None):
        super().__init__(parent)
        self.init_ui()

    def init_ui(self):
        """搭建工步配置UI"""
        layout = QVBoxLayout(self)

        # 1. 标题区域
        title = QLabel("工步配置")
        title.setFont(QFont("Arial", 16, QFont.Bold))
        layout.addWidget(title)

        # 配置说明
        desc = QLabel("配置每个循环中的工步组合和数据处理方式")
        layout.addWidget(desc)

        # 2. 工步循环工具（自定义组件）
        self.workstep_tool = WorkstepCycleTool()
        layout.addWidget(self.workstep_tool)

        # 3. 底部按钮（上一步/下一步）
        btn_layout = QHBoxLayout()
        self.prev_btn = QPushButton("上一步：BMS列配置")
        self.prev_btn.setIcon(QIcon.fromTheme("go-previous"))
        self.prev_btn.clicked.connect(self.on_prev_clicked)
        self.next_btn = QPushButton("下一步：数据处理")
        self.next_btn.setIcon(QIcon.fromTheme("go-next"))
        self.next_btn.clicked.connect(self.on_next_clicked)
        btn_layout.addWidget(self.prev_btn)
        btn_layout.addStretch()
        btn_layout.addWidget(self.next_btn)
        layout.addLayout(btn_layout)

    def get_workstep_config(self):
        """获取工步配置（工步组合列表）"""
        return self.workstep_tool.get_small_cycle_list()

    def on_prev_clicked(self):
        """上一步按钮点击事件"""
        # 由主窗口处理切换Tab
        self.prev_clicked.emit()

    def on_next_clicked(self):
        """下一步按钮点击事件"""
        # 由主窗口处理切换Tab
        self.next_clicked.emit()
